package com.scg.java_baidu_check;

import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DrawerNavigationAdapter extends BaseAdapter {

	private ImageView menuIcon;
	private TextView menuText;
	private ArrayList<SimpleEntry<Integer, String>> list;
	private Context context;

	public DrawerNavigationAdapter(Context context,
			ArrayList<SimpleEntry<Integer, String>> list) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater mInflater = LayoutInflater.from(context);
			convertView = mInflater.inflate(
					R.layout.drawer_list_item, null);

		}

		menuIcon = (ImageView) convertView.findViewById(R.id.menuIcon);
		menuText = (TextView) convertView.findViewById(R.id.menuText);

		menuIcon.setImageResource(list.get(position).getKey());
		menuText.setText(list.get(position).getValue());
		return convertView;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater mInflater = LayoutInflater.from(context);
			convertView = mInflater.inflate(
					R.layout.drawer_list_item, null);

		}

		menuIcon = (ImageView) convertView.findViewById(R.id.menuIcon);
		menuText = (TextView) convertView.findViewById(R.id.menuText);

		menuIcon.setImageResource(list.get(position).getKey());
		menuText.setText(list.get(position).getValue());
		return convertView;
	}
}
